﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8" />
    <title>流程详情</title>
    <link href="../lib/layui/css/layui.min.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script type="text/javascript" src="../linq.js/linq.js"></script>
    <script src="../lib/cookie/cookie.js"></script>
</head>
<body style="background-color:#eeeeee">
    <div class="x-nav" style="background-color:#ffffff">
        <span class="layui-breadcrumb">
            <a href="">流程配置</a>
            <a>
                <cite>配置文件列表</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh-1"></i>
        </a>
    </div>
    <div class="x-body">
        <div class="layui-col-md12" style="width:auto">
            <div class="layui-card" style="margin-left:0px">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" name="processForm" id="processForm" lay-filter="processForm" >
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="开始修改日" name="start" id="start">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="截止修改日" name="end" id="end">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="请输入文件名(支持模糊匹配)" name="fname" id="fname">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input class="layui-input" placeholder="请输入文件路径(支持模糊匹配)" name="fpath" id="fpath">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" type="button" lay-submit="" id="sreach"  lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i>
                            </button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <span style="display:none" id="parentpath"></span>
                    <button class="layui-btn" id="addfile" style="display:none">
                        <i class="layui-icon">&#xe61d;</i>添加文书
                    </button>
                    <button class="layui-btn" type="button" onclick="addProcessFile(this)">
                        <i class="layui-icon"></i>添加配置文件
                    </button>
                </div>
                <div class="layui-card-body" style="">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <!--<th width="20">
                                    <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
                                </th>-->
                                <th>文件名</th>
                                <th>备注</th>
                                <th>文件路径</th>
                                <th>文件大小</th>
                                <th>创建时间</th>
                                <th>修改时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody id="table_id">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript">
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            layui.jquery("#parentpath").html(theRequest.dir);
            return theRequest;
        }
        layui.$().ready(function () {
            var $ = layui.$;
            formLoad();
        });
        layui.$("#sreach").on("click", function (e) {
            formLoad();
        })
        
        function formLoad() {
            layui.jquery.ajax({
                type: "get",
                headers: {
                    user: getCookie("userinfo"),
                    version: getCookie("version")
                },
                url: localStorage.getItem('hosttingaddr') + "/Manager/ProcessCfgFile/Index?dir=" + getrequest().dir,
                /*                method: 'GET',*/
                data: layui.$('#processForm').serialize(),
                success: function (res) {
                    var html = "";
                    for (var i = 0; i < res.length; i++) {

                        var htmltemp = "<tr cate-id='" + res[i].currentId + "' fid='" + res[i].parentId + "'>";
                        //htmltemp += "<td><div lay-skin=\"primary\" data-id='" + res[i].currentId + "'><i class=\"layui-icon\">&#xe605;</i></div></td>";
                        htmltemp += "<td>";
                        for (var j = 0; j < res[i].level; j++) {
                            htmltemp += "<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>";
                        }
                        if (Enumerable.from(res).where(function (x) { return x.parentId == res[i].currentId; }).toArray().length > 0) {
                            htmltemp += "<i class=\"layui-icon x-show\" status='false'>&#xe625;</i>" + res[i].name;
                        } else {
                            htmltemp += "<span>&nbsp;&nbsp;&nbsp;&nbsp;" + res[i].name + "</span>";
                        }
                        htmltemp += " </td>";

                        htmltemp += "<td>" + res[i].note + "</td>";
                        htmltemp += "<td>" + res[i].parentPath + "</td>";
                        htmltemp += "<td>" + res[i].fileSize + "</td>";
                        htmltemp += "<td>" + res[i].createdTime + "</td>";
                        htmltemp += "<td>" + res[i].updateTime + "</td>";
                        htmltemp += "<td class=td-manage\"> <span style=\"display: none\">" + res[i].path + "</span>";

                        if (res[i].ctype == "F") {
                            htmltemp += "<a id=\"\" title=\"查看\"  href=\"javascript:;\">";
                            htmltemp += "<i class=\"layui-icon\">&#xe63c;</i>查看";
                            htmltemp += "</a>";
                            htmltemp += "<a title=\"删除\" href=\"javascript:;\">";
                            htmltemp += "<i class=\"layui-icon\">&#xe640;</i>删除";
                            htmltemp += "</a>";
                            htmltemp += "<a title=\"下载\" href=\"javascript:;\">";
                            htmltemp += "<i class=\"layui-icon\">&#xe640;</i>下载";
                            htmltemp += "</a>";
                        }
                        htmltemp += "</td >";
                        htmltemp += "</tr >";
                        html += htmltemp;
                    }
                    layui.jquery("#table_id").html(html);
                    // 栏目多级显示效果
                    layui.jquery('.x-show').click(function () {
                        $ = layui.$;
                        if ($(this).attr('status') == 'true') {
                            $(this).html('&#xe625;');
                            $(this).attr('status', 'false');
                            cateId = $(this).parents('tr').attr('cate-id');
                            $("tbody tr[fid=" + cateId + "]").show();
                        } else {
                            cateIds = [];
                            $(this).html('&#xe623;');
                            $(this).attr('status', 'true');
                            cateId = $(this).parents('tr').attr('cate-id');
                            getCateId(cateId);
                            for (var i in cateIds) {
                                $("tbody tr[cate-id=" + cateIds[i] + "]").hide().find('.x-show').html('&#xe623;').attr('status', 'true');
                            }
                        }
                        var cateIds = [];
                        function getCateId(cateId) {

                            $("tbody tr[fid=" + cateId + "]").each(function (index, el) {
                                id = $(el).attr('cate-id');
                                cateIds.push(id);
                                getCateId(id);
                            });
                        }
                    });
                    //查看详细
                    layui.$("a[title='查看']").click(function () {
                        $ = layui.$;
                        //获取span的内容；
                        var fileN = $(this).prev().html();
                        openCfgFile(fileN);
                    });
                }
            });
        }
       

        // 设置筛选条件开始日期为日期控件
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
                , type: 'datetime'
            });
            laydate.render({
                elem: '#end' //指定元素
                , type: 'datetime'
            });
        });

        // 弹窗显示流程配置文件的内容
        function openCfgFile(fileN) {
            layer.open({
                type: 2,
                title: '流程配置文件内容',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['1200px', '520px'],
                content: 'processdetail.html?fileName=' + fileN// iframe链接地址
            });
        };

        // 编辑配置文件
        function editCfgFile(obj, fileName) {
            layer.open({
                type: 2,
                title: '编辑流程配置文件内容',
                maxmin: true,
                shadeClose: true,
                area: ['1000px', '520px'],
                content: 'Edit/ProcessCfgFile?fileName=' + fileName// iframe链接地址
            });
        }

        // 删除文件
        function member_del(obj, fileN) {
            fileP = Base64.encode(fileN);
            layer.confirm('确认要删除吗？', function (index) {
                //发异步删除数据
                $(obj).parents("tr").remove();
                $.ajax({
                    type: "post",
                    url: "DelFile",
                    data: "fileName=" + fileN,
                    success: function (data) {

                    }
                });
                layer.msg('已删除!', { icon: 1, time: 1000 });
            });
        }

        // 下载文件
        function downloadFile(obj, fileN) {
            var arr = fileN.split('/');
            layer.open({
                type: 2,
                title: '下载配置文件',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['300px', '180px'],
                content: 'DownLoadFile/ProcessCfgFile?fileName=' + fileN// iframe链接地址
            });
        }

        // 添加流程配置文件
        function addProcessFile(obj) {
            var dirstr = getrequest().dir;
            layer.open({
                type: 2,
                title: '新增流程配置文件',
                maxmin: true,
                shadeClose: true,
                area: ['800px', '520px'],
                content: 'addfile.html?dir=' + dirstr// iframe链接地址
            });
        }

    </script>
</body>
</html>